//
//  HMSinaLoginView.swift
//  ZJCSina
//
//  Created by 朱建超 on 16/11/13.
//  Copyright © 2016年 itHeiMa. All rights reserved.
//

import UIKit
import SnapKit

class HMSinaLoginView: UIView {

    //MARK:外界设置界面信息的方法
    func upDateUI(title : String , imageName : String , isHome : Bool) {
        
        self.descLabel.text = title
        self.circleView.image = UIImage(named : imageName)
        if isHome == true {
            
            //执行动画
            startAnimation()
            
        }else{
        
        //不是首页
            //隐藏遮盖图片和房子的图片
            self.houseView.isHidden = true
            self.zheGaiView.isHidden = true
        
        }
        
    }
    
    //动画效果
    private func startAnimation() {
        
        let animation = CABasicAnimation(keyPath: "transform.rotation")
        
        //设置属性
        animation.repeatCount = MAXFLOAT
        animation.toValue = M_PI * 2
        animation.duration = 15
        
        //isRemovedOnCompletion: 当动画效果啊完成之后就从图层移除,设置为false 就不会被移除图层, 默认值值是true
        animation.isRemovedOnCompletion = false
        
        //将动画添加到图层上
        circleView.layer.add(animation, forKey: nil)
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        
        backgroundColor = UIColor.init(white: 237.0 / 255.0, alpha: 1)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: 设置UI界面
    private func setupUI() {
        
        addSubview(circleView)
        addSubview(zheGaiView)
        addSubview(houseView)
        addSubview(descLabel)
        addSubview(dengLuButton)
        addSubview(zhuCeButton)
        
        circleView.snp.makeConstraints { (make) in
            
            make.centerX.equalTo(self.snp.centerX)
            make.centerY.equalTo(self.snp.centerY).offset(-80)
            
        }
        
        zheGaiView.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.centerY.equalTo(self.snp.centerY).offset(-70)
        }
        
        houseView.snp.makeConstraints { (make) in
            make.center.equalTo(circleView.snp.center)
        }
        
        descLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(circleView.snp.centerX)
            make.centerY.equalTo(circleView.snp.centerY).offset(120)
        }
        
        dengLuButton.snp.makeConstraints { (make) in
            make.left.equalTo(descLabel.snp.left)
            make.top.equalTo(descLabel.snp.bottom).offset(20)
            make.width.equalTo(100)
        }
        
        zhuCeButton.snp.makeConstraints { (make) in
            make.right.equalTo(descLabel.snp.right)
            make.top.equalTo(descLabel.snp.bottom).offset(20)
            make.width.equalTo(100)
        }
        
    }
    
    //实例化子控制器
    //圈圈
    private lazy var circleView : UIImageView = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_image_smallicon"))
    //大房子
    private lazy var houseView : UIImageView = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_image_house"))
    //label
    private lazy var descLabel: UILabel = {
        
        let descLabel = UILabel(title: "关注一些人，回到这里看看有什么惊喜", font: 15, textColor: UIColor.darkGray)
        
        //设置label的最大宽度
        descLabel.preferredMaxLayoutWidth = 220
        
        //设置行数和字体居中
        descLabel.numberOfLines = 0
        descLabel.textAlignment = .center
        
        return descLabel
    }()
    
    //登录按钮
    lazy var dengLuButton: UIButton = {
        let button = UIButton(title: "登录", font: 15, textColor: UIColor.darkGray)
        
        button.setBackgroundImage(#imageLiteral(resourceName: "common_button_white"), for: .normal)
        
        return button
    }()
    
    //注册按钮
    lazy var zhuCeButton: UIButton = {
        
        let button = UIButton(title: "注册", font: 15, textColor: UIColor.orange)
        
        button.setBackgroundImage(#imageLiteral(resourceName: "common_button_white"), for: .normal)
        
        return button
    }()
    
    //遮盖图片
    private lazy var zheGaiView = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_mask_smallicon"))

}
